package com.libweb.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.libweb.common.Util;
import com.libweb.model.dao.MemberDao;
import com.libweb.model.dto.Member;

@WebServlet("/member/register.action")
public class MemberRegisterServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		String memberId = req.getParameter("memberId");
		String passwd = req.getParameter("passwd");
		passwd = Util.getHashedString(passwd, "SHA-1");
		String name = req.getParameter("name");
		String address = req.getParameter("address");
		String phoneno = req.getParameter("phoneno");
				
		Member member = new Member();
		member.setMemberId(memberId);
		member.setPasswd(passwd);
		member.setName(name);
		member.setAddress(address);
		member.setPhoneNo(phoneno);
		
		MemberDao dao = new MemberDao();
		dao.insertMember(member);
		
		//등록 후 홈 화면으로 이동
		//HttpResponse.sendRedirect: 지정된 경로로 요청을 재전송
		resp.sendRedirect("/libweb/home.action");
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}